package cn.wolfcode.trip.base.util;

import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {
    public static final String USER_IN_SESSION="USER_IN_SESSION";

    //获取session对象
    public static HttpSession getSession() {
        return ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes()))
                .getRequest().getSession();
    }
    //保存用户信息到session中
    public static void setCurrentUser(User user) {
        getSession().setAttribute(USER_IN_SESSION, user);
    }

    //获取session中的用户
    public static User getCurrentUser() {
        return (User) getSession().getAttribute(USER_IN_SESSION);
    }



}
